package DailyPractice.Day28;

import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * 反转部分链表
 * @author lumin
 * @date 2022/05/25 22:24
 **/
public class Num1 {
    public static class Node {

        public int value;
        public Node next;

        public Node(int value) {
            this.value = value;
        }
    }

    public static Node reversePart(Node head, int from, int to) {
        Node node1 = head;
        Node begin = null;
        Node end = null;
        int len = 0;
        while (node1 != null) {
            len++;
            // 找到反转部分的前一个结点
            begin = len == from - 1 ? node1 : begin;
            // 找到反转部分的后一个结点
            end = len == to + 1 ? node1 : end;
            node1 = node1.next;
        }
        if (from > to || from < 1 || to > len) {
            return head;
        }
        node1 = begin == null ? head : begin.next;
        Node node2 = node1.next;
        node1.next = end;
        Node next = null;
        while (node2 != end) {
            next = node2.next;
            node2.next = node1;
            node1 = node2;
            node2 = next;
        }
        if (begin != null) {
            begin.next = node1;
            return head;
        } else {
            return node1;
        }
    }

    public static void printList(Node head) {
        while (head != null) {
            System.out.print(head.value +" ");
            head = head.next;
        }
        System.out.println();
    }

    public static Node listGenerator(int length, String[] numbers) {
        Node head = new Node(Integer.parseInt(numbers[0]));
        Node cur = head;
        for (int i = 1; i < length; i++) {
            cur.next = new Node(Integer.parseInt(numbers[i]));
            cur = cur.next;
        }
        cur.next = null;
        return head;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(bufferedReader.readLine());
        String[] numbers = bufferedReader.readLine().split(" ");
        String[] parameters = bufferedReader.readLine().split(" ");
        int L = Integer.parseInt(parameters[0]);
        int R = Integer.parseInt(parameters[1]);
        Node head = listGenerator(n, numbers);
        head = reversePart(head, L, R);
        printList(head);
    }
}